package com.ettractions.kiosk.services
{
	import com.ettractions.kiosk.assets.AssetsLoadRequest;
	import com.ettractions.kiosk.assets.AssetsLoader;
	import com.ettractions.kiosk.assets.AssetsStore;
	import com.ettractions.kiosk.events.ImagePreloadServiceEvent;
	import com.ettractions.kiosk.vo.BrochureVO;
	
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import org.robotlegs.mvcs.Actor;

	public class ImagePreloadService extends Actor
	{
		public function preloadImages(brochures:Vector.<BrochureVO>):void
		{
			var loader:AssetsLoader = new AssetsLoader();
			var request:AssetsLoadRequest = new AssetsLoadRequest();
			
			for each (var brochure:BrochureVO in brochures)
			{
				request.addPath(brochure.media.thumbnailPath);
				request.addPath(brochure.media.contentImagePaths[0]);
			}
			
			loader.loadAssets(request);
			loader.addEventListener(Event.COMPLETE, handleLoaderComplete);
		}
		
		private function handleLoaderComplete(event:Event):void
		{
			var loader:AssetsLoader = AssetsLoader(event.target);
			
			loader.removeEventListener(Event.COMPLETE, handleLoaderComplete);
			
			eventDispatcher.dispatchEvent(new ImagePreloadServiceEvent(ImagePreloadServiceEvent.IMAGE_PRELOAD_COMPLETE, loader.assets));
		}
	}
}